package com.omo.infrastructure.persistent.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.omo.domain.machine.model.entity.MachineProductionEntity;
import com.omo.domain.machine.repository.IMachineProductionRepository;
import com.omo.infrastructure.persistent.dao.IMachineProductionTestDao;
import com.omo.infrastructure.persistent.po.MachineProductionTest;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

@Repository
public class MachineProductionRepository implements IMachineProductionRepository {
    @Resource
    private IMachineProductionTestDao machineProductionTestDao;

    @Override
    public List<MachineProductionEntity> queryMachineProduction(String machineName) {
        QueryWrapper<MachineProductionTest> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda()
                .eq(MachineProductionTest::getMachineName, machineName)
                .eq(MachineProductionTest::getIsDeleted, 1)
        ;

        return machineProductionTestDao.selectList(queryWrapper).stream().map(x -> MachineProductionEntity.builder()
                .machineSn(x.getMachineSn())
                .machineName(x.getMachineName())
                .testTime(x.getTestTime())
                .version(x.getVersion())
                .production(x.getProduction())
                .preProduction(x.getPreProduction())
                .difference(x.getDifference())
                .updateTime(x.getUpdateTime())
                .build()).collect(Collectors.toList());
    }
}
